package com.wiegand.content.contents {
	import com.caurina.transitions.Tweener;
	import com.wiegand.content.AbstractContent;
	import com.wiegand.content.contents.textcontent.TextScene3D;

	import flash.display.Sprite;
	import flash.geom.Rectangle;

	/**
	 * @author gandy
	 */
	 
	public class TextContent extends AbstractContent {
		private var _textScene : TextScene3D;
		
		public function TextContent(xml:XMLList) {
			super(xml);
		}
		
		override public function init() : void {
			_container = new Sprite();
			_container.alpha = 0;
			addChild(_container);
			
			_textScene = new TextScene3D(_xml.textscene);
			_container.addChild(_textScene);
		}
		
		override public function open(delay : Number = 0) : void {
			_textScene.x = stage.stageWidth/2 + int(_xml.textscene.@x);
			_textScene.y = stage.stageHeight/2 + int(_xml.textscene.@y);
			_textScene.updateBackground( new Rectangle(-stage.stageWidth*2, -stage.stageHeight*2, stage.stageWidth*4, stage.stageHeight*4));
			
			_textScene.open(1);
			
			Tweener.removeTweens(_container);
			Tweener.addTween(_container,{alpha:1,delay:delay,time:1,transition:"linear",onComplete:callOpen});
		}
		
		override public function close(delay : Number = 0) : void {
			_textScene.close();
			
			Tweener.removeTweens(_container);
			Tweener.addTween(_container,{alpha:0,delay:delay,time:1,transition:"linear",onComplete:callClosed});
		}
		
		override public function destroy() : void {
			_container.removeChild(_textScene);
			_textScene.destroy();
			Tweener.removeTweens(_container);
			removeChild(_container);
		}
		
	}
}
